<?php

namespace app\api\controller;

use app\services\CustomerService;
use plugin\admin\app\model\Message;
use support\Request;

class CustomerServiceController
{
    public function customerServiceList(Request $request)
    {
        try {
            $page = $request->post('page', 1);
            $length = $request->post('length', 10);

            $data = CustomerService::list(get_user_id(), $page, $length, true);
            return ok_rsp('成功', $data);
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }

    public function addCustomerServiceMessage(Request $request)
    {
        try {
            $messageType = $request->post('message_type');
            $content = $request->post('content');

            CustomerService::add(get_user_id(), $messageType, $content, Message::ROLE_USER);
            return ok_rsp('成功');
        } catch (\Exception $e) {
            return err_rsp($e->getMessage());
        }
    }
}